﻿//
// XN4SL - Xna Framework for Silverlight.
//
using System;
using System.Windows.Controls;

namespace Xn4Sl.Framework.Audio
{
    /// <summary>
    /// Provides a loaded sound resource.
    /// </summary>
    public sealed class SoundEffect : IDisposable
    {
        /// <summary>
        /// Gets a value that indicates whether the object is disposed.
        /// </summary>
        private bool isDisposed;
        public bool IsDisposed
        {
            get
            {
                return this.isDisposed;
            }
        }

        /// <summary>
        /// Gets or sets the master volume that affects all SoundEffectInstance sounds.
        /// </summary>
        private static float masterVolume = 1;
        public static float MasterVolume
        {
            get
            {
                return masterVolume;
            }
            set
            {
                masterVolume = value;
            }
        }

        /// <summary>
        /// Gets or sets the asset name of the SoundEffect.
        /// </summary>
        private string name;
        public string Name 
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        /// <summary>
        /// Returns the speed of sound: 343.5 meters per second.
        /// </summary>
        public static float SpeedOfSound { get; set; }

        /// <summary>
        /// Releases the resources used by the SoundEffect.
        /// </summary>
        public void Dispose()
        {
            this.isDisposed = true; 
        }

        /// <summary>
        /// Creates a new SoundEffectInstance and plays it.
        /// </summary>
        /// <returns>A new, playing, SoundEffectInstance.</returns>
        public SoundEffectInstance Play()
        {
            SoundPlayer.Play(this);
            return new SoundEffectInstance();
        }
    }
}
